package factorytest;


public class AnimalFactory {

	public static Animal createAnimal(String type){
		StringBuffer sb=new StringBuffer();
		System.out.println("type: "+type);
		sb.append(type.substring(0,1).toUpperCase());
		sb.append(type.substring(1).toLowerCase());
		try {
			System.out.println("sb.toString: "+sb.toString());
			String str=sb.toString();
			return (Animal)Class.forName("factorytest."+str).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
}
